package com.broadengate.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;
import com.broadengate.form.SetPoundageForm;
import com.broadengate.service.AdminService;
import com.broadengate.model.Atminfo;

public class SetPoundageAction extends DispatchAction {

	private AdminService adminService;
	
	/******
	 * 管理员设置手续费率
	 * 核心功能由调用AdminService对象的方法setPoundage()，findAtminfo()实现
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return ActionForward 对象
	 */
	public ActionForward setPoundage(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response){
		
		System.out.println("SetPoundageAction 进入");
		SetPoundageForm setPoundageForm =(SetPoundageForm)form;
		float poundage = Float.parseFloat(setPoundageForm.getPoundage());
		Atminfo atminfo=adminService.findAtminfo();
		atminfo.setPoundage(poundage);
		 HttpSession session=request.getSession();
		try {
			session.setAttribute("again", "1");
			session.setAttribute("poundage", setPoundageForm.getPoundage());
			adminService.setPoundage(atminfo);
			return mapping.findForward("success");
		} catch (Exception e) {
			e.printStackTrace();
			return mapping.findForward("fail");
		}
	}

	public AdminService getAdminService() {
		return adminService;
	}

	public void setAdminService(AdminService adminService) {
		this.adminService = adminService;
	}
	
}
